<template>
  <div id="gashapon">  
  
  <el-form ref="form"  label-width="0px">  
    <el-row>

        <el-col :span="24" style="text-align: right;"> 
           <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="sxf_but()">手续费</el-button>
           <!-- <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="xs_but()">全局系数</el-button>  -->
           <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="go_but()">中奖纪录</el-button> 
           <el-button type="primary" class="custom_color_button" style="margin-bottom:10px;" @click="reach_but()">新增</el-button>                   
        </el-col>
   
  </el-row>
  </el-form >

   <!-- 渲染数据list -->
   <gashapon-list :datalist="datalist" @up_list_fun="list_fun"> </gashapon-list>

      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>
   

       <!-- 新增 -->
    <el-dialog title="新增" :visible.sync="reach_mtk"  width="450px">
        <div style="width:100%;"> 

        <el-form ref="form"   label-width="70px" style="width:100%;">
              
              <el-form-item label="名称">
                    <el-input    v-model="reach_form.title" placeholder="名称"></el-input>
              </el-form-item> 
              <el-form-item label="分享人数">
                    <el-input    v-model="reach_form.people" placeholder="分享人数"></el-input>
              </el-form-item> 
              <el-form-item label="经验值">
                    <el-input    v-model="reach_form.number" placeholder="经验值"></el-input>
              </el-form-item> 
              <el-form-item label="扭蛋次数">
                    <el-input    v-model="reach_form.must_number" placeholder="经验值"></el-input>
              </el-form-item>
              
               <el-form-item :label="'选择' + variable_name4">
                      <el-select  v-model="limits_form.select_num"  placeholder="请选择" style="width:100%;">
                          <el-option  v-for="(item,index) in limits_form.select_data" :key="index" :label="item.title" :value="item.maid"></el-option>
                       </el-select>
                 </el-form-item>

              <el-form-item label="开放时间">
                    <el-date-picker type="date"   placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="reach_form.time1" ></el-date-picker>
              </el-form-item>  
              <el-form-item label="结束时间">
                    <el-date-picker type="date"   placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="reach_form.time2" ></el-date-picker>
              </el-form-item>   
                                  
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;"  @click="reach_but_qr">确认</el-button>
            </div>

        </div> 
    </el-dialog>



       <!-- 全局系数 -->
    <el-dialog title="全局系数" :visible.sync="xs_mtk"  width="450px">
        <div style="width:100%;"> 

        <el-form ref="form"   label-width="70px" style="width:100%;">              
              <el-form-item label="" label-width="0px">
                    <el-input    v-model="xs_form.number" placeholder="请输入全局系数"></el-input>
              </el-form-item>                                  
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;"  @click="xs_but_qr">确认</el-button>
            </div>

        </div> 
    </el-dialog>




       <!-- 手续费 -->
    <el-dialog title="手续费" :visible.sync="sxf_mtk"  width="450px">
        <div style="width:100%;"> 

        <el-form ref="form"   label-width="70px" style="width:100%;">              
              <el-form-item label="" label-width="0px">
                    <el-input    v-model="sxf_form.number" placeholder="请输入手续费"></el-input>
              </el-form-item>                                  
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;"  @click="sxf_but_qr">确认</el-button>
            </div>

        </div> 
    </el-dialog>

  



   
      
  </div>
</template>

<script>
import GashaponList from '@/view/Activity/GashaponList'
export default {
  name: 'gashapon',
  data () {
    return {
        datalist:[],
        page:1,
        count:0,
        reach_mtk:false,
        reach_form:{
            title:'',
            people:'',
            number:'',
            time1:'',
            time2:'',
            must_number:''
        },
        limits_form:{
            select_data:[],
            select_num:'',
        },
        xs_mtk:false,
        xs_form:{
           number:''
        },
        sxf_mtk:false,
        sxf_form:{
            number:''
        },
    }
  },
 components:{
    GashaponList
  },
  created(){
     this.gz_list()
     this.list_fun()
  },
  mounted (){
    
  },
  methods: { 
      gz_list(){
        this.post("/manor/listOfData", {
             
	        }).then(res => {
                this.limits_form.select_data = res.result.list
                //console.log(res)
         })
      },
      list_fun(){
           this.post("/lottery_shake/listOfData", {
              page:this.page,
	         }).then(res => {
            this.count = res.result.count
            this.datalist = res.result.list
            //console.log(this.datalist)
          })
      },
      reach_but(){
          this.reach_mtk = true
           this.reach_form.title = '',
          this.reach_form.time1 = ''
          this.reach_form.time2 = ''
          this.reach_form.people = ''
          this.reach_form.number = ''
          this.limits_form.select_num = ''
          this.reach_form.must_number - ''
      },
      reach_but_qr(){
           this.post("/lottery_shake/create", {
                    title:this.reach_form.title,
                    start:this.reach_form.time1,
                    end:this.reach_form.time2,
                    experience:this.reach_form.number,
                    invite_count:this.reach_form.people,
                    manor_limit:this.limits_form.select_num,
                    must_number:this.reach_form.must_number
                }).then(res => {

                    if(res.error_code == 0){
                      this.open1(res.result,'success')  //提示框
                      this.reach_mtk = false
                      this.list_fun()
                    }else {
                    this.open1(res.message,'warning')
                    }

              })
      },
      xs_fun(){
           this.post("/lottery_shake/rewardScale", {                
                }).then(res => {
                   //console.log(res.result.cash_reward_scale,"fff")
                   this.xs_form.number = res.result.cash_reward_scale
              })
      },
      xs_but(){
           this.xs_mtk = true
           this.xs_fun()
      },
      xs_but_qr(){
            this.post("/lottery_shake/setRewardScale", {
                    cash_reward_scale:this.xs_form.number
                }).then(res => {

                    if(res.error_code == 0){
                      this.open1(res.result,'success')  //提示框
                      this.xs_mtk = false
                    }else {
                    this.open1(res.message,'warning')
                    }

              })
      },
      sxf_fun(){
         this.post("/lottery_shake/serviceCharge", {                
                }).then(res => {
                   //console.log(res.result,"sss")
                   this.sxf_form.number = res.result.service_charge
              })
      },
      sxf_but(){
           this.sxf_mtk = true
           this.sxf_fun()
      },
      sxf_but_qr(){
          this.post("/lottery_shake/setServiceCharge", {
                    service_charge:this.sxf_form.number
                }).then(res => {

                    if(res.error_code == 0){
                      this.open1(res.result,'success')  //提示框
                      this.sxf_mtk = false
                    }else {
                    this.open1(res.message,'warning')
                    }

              })
      },
      go_but(){
        this.$router.push({
          path: '/index/detailsgashapon',
          query: {
            //name:row.name,
            // id:row.uid,
            // type:type,
            // typename:typename
          }
        })
      },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>

</style>
